package com.adams.util.config;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * File Name : ConfigAction.java
 * 
 * @Description : 配置帮助工具类
 * @author 904941
 */
public class ConfigUtil
{

	/**
	 * 
	 * Description : 加载配置文件（jdbc.properties sysconfig.properties）
	 * 
	 * @return Properties 加载的配置文件
	 * 
	 */
	public static Properties loadProperties(String fileName, String fileDir)
	{
		Properties p = new Properties();
		InputStream is = null;
		try
		{
			is = new FileInputStream(fileDir);
		} catch (FileNotFoundException e)
		{
			throw new RuntimeException("loading" + fileName + " file error");
		}

		try
		{
			if (is != null)
			{
				p.load(is);
				is.close();
			}
		} catch (IOException e)
		{
			throw new RuntimeException("loading " + fileName + " file error");
		}
		return p;
	}

	/**
	 * 
	 * Description : 在特殊字符显示时将'\'还原成\显示
	 * 
	 * @return 结果字符串
	 * 
	 */
	public static String replaceSlash(String src)
	{
		if (src == null)
			return null;
		StringBuilder buffer = new StringBuilder(src.length() * 2);
		for (int i = 0; i < src.length(); i++)
		{
			char c = src.charAt(i);
			if (c == '\\')
				buffer.append("\\\\");
			else
				buffer.append(c);
		}
		return buffer.toString();
	}
}
